<?php

namespace App\Trip\Enums;

use App\Trip\Orders\TripType;
use Exception;
use Str;

/**
 * @method bool  isTrain()
 * @method bool  isPlane()
 * @method bool  isHotel()
 */
enum TripTypes: int
{
    case TRAIN = 1;// 这里只能定义常量
    case PLANE = 2;// 这里只能定义常量
    case HOTEL = 4;// 这里只能定义常量

    public function trip_type(): int
    {
        return match ($this) {
            self::TRAIN => TripType::TRIP_TYPE_TRAIN,
            self::PLANE => TripType::TRIP_TYPE_PLANE,
            self::HOTEL => TripType::TRIP_TYPE_HOTEL,
        };
    }

    public function trip_tag(): string
    {
        return match ($this) {
            self::TRAIN => 'train',
            self::PLANE => 'plane',
            self::HOTEL => 'hotel',
        };
    }

    public function order_flag(): string
    {
        return match ($this) {
            self::TRAIN => 'T',
            self::PLANE => 'P',
            self::HOTEL => 'H',
        };
    }


    /**
     * @throws Exception
     */
    public function __call(string $name, array $arguments)
    {
        // is 方法 魔术
        if (mb_substr($name, 0, 2) == 'is') {
            $bn      = Str::replaceFirst("is", '', $name);
            $bnUpper = strtoupper($bn);
            if ($bnUpper != $this->name) {
                return false;
            }
            return true;
        }

        throw new Exception("暂不支持该方法");
    }
}
